"""hte URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
from django.conf.urls import include, url
from apps.mge.views import site_index
from apps.mge.views import set_language
from django.views.decorators.cache import cache_page
from django.utils.translation import get_language
from django.views.i18n import JavaScriptCatalog
from django.conf import settings
from apps.base_hte.views import site_index_fsc, get_js_resolver

urlpatterns = [
    path('admin/', admin.site.urls),

    # app urls
    path('accounts/', include(('apps.accounts.urls', 'apps.accounts'), namespace='accounts')),
    path('analysis/', include(('apps.analysis.urls', 'apps.analysis'), namespace='analysis')),
    path('material/', include(('apps.material.urls', 'apps.material'), namespace='material')),
    path('mlplatform/', include(('apps.mlplatform.urls', 'apps.mlplatform'), namespace='mlplatform')),
    path('search/', include(('apps.search.urls', 'apps.search'), namespace='search')),
    path('storage/', include(('apps.storage.urls', 'apps.storage'), namespace='storage')),
    path('imagerecognize/', include(('apps.imagerecognize.urls', 'apps.imagerecognize'), namespace='imagerecognize')),

    # api_v1 url
    # include只写一个即可，写了第二个则可以不写namespace
    path(r'accounts/api/v1/', include(('apps.accounts.api_v1_urls', 'apps.accounts'), namespace='accounts_api_v1')),
    path(r'analysis/api/v1/', include(('apps.analysis.api_v1_urls', 'apps.analysis'), namespace='analysis_api_v1')),
    path(r'material/api/v1/', include(('apps.material.api_v1_urls', 'apps.material'), namespace='material_api_v1')),
    path(r'search/api/v1/', include(('apps.search.api_v1_urls', 'apps.search'), namespace='search_api_v1')),
    path('storage/api/v1/', include(('apps.storage.api_v1_urls', 'apps.storage'), namespace='storage_api_v1')),
    path('mlplatform/api/v1/', include(('apps.mlplatform.api_v1_urls', 'apps.mlplatform'), namespace='mlplatform_api_v1')),
    path(r'mlplatform/api/v2/', include(('apps.mlplatform.api_v2_urls', 'apps.mlplatform'), namespace='mlplatform_api_v2')),
    # page view
    path(r'', site_index, name='site_index'),
    path(r'get-urls', get_js_resolver, name='site_urls'),
    path(r'jsi18n/', cache_page(86400, key_prefix='js18n-%s' % get_language())(JavaScriptCatalog.as_view()), name='javascript-catalog'),
    path(r'set-language', set_language, name='site_set_language'),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

# if settings.DEBUG:
#     urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
